<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>二维码生成器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .container {
            text-align: center;
        }
        #qrcode {
            margin: 20px auto;
            padding: 20px;
        }
        #textInput {
            width: 80%;
            padding: 10px;
            font-size: 16px;
            margin: 10px;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 10px 2px;
            cursor: pointer;
            border: none;
            border-radius: 4px;
        }
        button:hover {
            background-color: #45a049;
        }
        #downloadBtn {
            background-color: #008CBA;
        }
        #downloadBtn:hover {
            background-color: #007B9A;
        }
        #qrcodeContainer {
            margin: 20px 0;
        }
        .instructions {
            background-color: #e7f3ff;
            border-left: 6px solid #2196F3;
            margin: 20px 0;
            padding: 15px;
            text-align: left;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>二维码生成器</h1>
        <div class="instructions">
            <h3>使用说明：</h3>
            <ol>
                <li>在下方输入框中输入要显示的内容</li>
                <li>点击"生成二维码"按钮生成二维码</li>
                <li>点击"下载展示页面"按钮下载内容展示网页</li>
                <li>将展示页面部署到服务器上</li>
                <li>二维码将指向该页面并显示输入的内容</li>
            </ol>
        </div>
        <input type="text" id="textInput" placeholder="请输入要生成二维码的内容" />
        <br>
        <button id="generateBtn">生成二维码</button>
        <button id="downloadPageBtn">下载展示页面</button>
        <button id="downloadBtn" style="display: none;">下载二维码</button>
        <div id="qrcodeContainer">
            <div id="qrcode"></div>
        </div>
    </div>

    <script src="lib/qrcode.min.js"></script>
    <script>
        let qrCodeDataUrl = '';
        let pageContent = '';
        
        document.getElementById('generateBtn').addEventListener('click', function() {
            const textInput = document.getElementById('textInput').value;
            if (!textInput) {
                alert('请输入内容');
                return;
            }
            
            // 生成展示页面的示例URL（需要用户部署到实际服务器）
            const encodedContent = encodeURIComponent(textInput);
            const exampleUrl = `https://your-domain.com/content_display.html?content=${encodedContent}`;
            
            // 清空之前的二维码
            document.getElementById('qrcode').innerHTML = '';
            
            // 生成二维码
            const qrcode = new QRCode(document.getElementById('qrcode'), {
                text: exampleUrl,
                width: 200,
                height: 200,
                colorDark: "#0000FF",
                colorLight: "#ffffff",
                correctLevel: QRCode.CorrectLevel.H
            });
            
            // 显示下载按钮
            document.getElementById('downloadBtn').style.display = 'inline-block';
            
            // 保存页面内容供下载使用
            pageContent = `<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>内容展示</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            line-height: 1.6;
        }
        .content {
            margin-top: 20px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f9f9f9;
        }
    </style>
</head>
<body>
    <h1>内容展示页面</h1>
    <div class="content" id="displayContent">
        ${textInput}
    </div>
    
    <script>
        // 如果需要从URL参数获取内容，可以使用以下代码：
        /*
        const urlParams = new URLSearchParams(window.location.search);
        const content = urlParams.get('content');
        
        if (content) {
            const decodedContent = decodeURIComponent(content);
            document.getElementById('displayContent').innerText = decodedContent;
        }
        */
    <\/script>
</body>
</html>`;
            
            // 等待二维码渲染完成后获取图像数据
            setTimeout(() => {
                const canvas = document.querySelector('#qrcode canvas');
                if (canvas) {
                    qrCodeDataUrl = canvas.toDataURL('image/png');
                }
            }, 100);
        });
        
        document.getElementById('downloadBtn').addEventListener('click', function() {
            if (!qrCodeDataUrl) return;
            
            const link = document.createElement('a');
            link.href = qrCodeDataUrl;
            link.download = 'qrcode.png';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        });
        
        document.getElementById('downloadPageBtn').addEventListener('click', function() {
            const textInput = document.getElementById('textInput').value;
            if (!textInput) {
                alert('请输入内容');
                return;
            }
            
            // 如果还没有生成页面内容，则生成它
            if (!pageContent) {
                pageContent = `<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>内容展示</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            line-height: 1.6;
        }
        .content {
            margin-top: 20px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f9f9f9;
        }
    </style>
</head>
<body>
    <h1>内容展示页面</h1>
    <div class="content" id="displayContent">
        ${textInput}
    </div>
</body>
</html>`;
            }
            
            // 创建并下载文件
            const blob = new Blob([pageContent], { type: 'text/html;charset=utf-8' });
            const url = URL.createObjectURL(blob);
            const link = document.createElement('a');
            link.href = url;
            link.download = 'content_display.html';
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            URL.revokeObjectURL(url);
        });
    </script>
</body>
</html>